package com.sqx.modules.health.controller;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sqx.modules.health.common.Result;
import com.sqx.modules.health.entity.AppExplan;
import com.sqx.modules.health.service.IAppExplanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 康复方案表 前端控制器
 * </p>
 *
 * @author hsx
 * @since 2022-08-30
 */

@Api(value = "康复方案表", tags = "康复方案接口", description = "")
@RestController
@RequestMapping("/health/app/explan")
public class AppExplanController {
    @Autowired
    private IAppExplanService appExplanService;

    // 新增或更新
    @PostMapping("/save")
    @ApiOperation(value = "新增或更新康复方案表", notes = "新增或更新康复方案表")
    public Result save(@RequestBody AppExplan appExplan){
        return Result.success(appExplanService.save(appExplan));
    }

    // 根据ID删除
    @DeleteMapping("/del/{id}")
    @ApiOperation(value = "根据ID删除康复方案表", notes = "根据ID删除康复方案表")
    public Result delete(@PathVariable Integer id){
        return Result.success(appExplanService.removeById(id));
    }

    // 根据IDS删除
    @PostMapping("/del/batch")
    @ApiOperation(value = "根据IDS删除康复方案表", notes = "根据IDS删除康复方案表")
    public Result deleteBatch(@RequestBody List<Integer> ids){
        return Result.success(appExplanService.removeByIds(ids));
    }

    // 查询全部
    @GetMapping("/findAll")
    @ApiOperation(value = "查询全部康复方案表", notes = "查询全部康复方案表")
    public Result findAll(){
        return Result.success(appExplanService.list());
    }

    // 根据ID查询一条记录
    @GetMapping("/findOne")
    @ApiOperation(value = "根据ID查询一条记录康复方案表", notes = "根据ID查询一条记录康复方案表")
    public Result findOne(@PathVariable Integer id){
        return Result.success(appExplanService.getById(id));
    }

    // 分页查询
    @GetMapping("/findPage")
    @ApiOperation(value = "分页查询康复方案表", notes = "分页查询康复方案表")
    public Result findPage(@RequestParam Integer pageNum,@RequestParam Integer pageSize){
        QueryWrapper<AppExplan> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return  Result.success((List<AppExplan>)appExplanService.page(new Page<>(pageNum,pageSize),queryWrapper));
    }

    // 条件查询
    @GetMapping("/findConditionPage")
    @ApiOperation(value = "条件查询康复方案表", notes = "条件查询康复方案表")
    public Result findConditionPage(@RequestParam Map<String, String> params){
        QueryWrapper<AppExplan> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(ObjectUtil.isNotEmpty(params.get("uid")), "uid", params.get("uid"))
                .eq(ObjectUtil.isNotEmpty(params.get("type")), "type", params.get("type"));
        queryWrapper.orderByDesc("createtime");
        List<AppExplan> getData =(List<AppExplan>)appExplanService.list(queryWrapper);
        return  Result.success(getData);
    }

}

